#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
const int k=131;
int n;
ull ha[1001];
bool w[1002],op[1002];
string a[1001];
int main(){
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++){
		bool pi=0,used=0;
		cin>>a[i];
		if(a[i][0]=='S'){
			used=1;
			//E
			cin>>a[i];
			op[i]=0;
			bool ok=0,g=0;
			int len=a[i].length(),sum=0,num=0;
			for(int j=0;j<len;++j){
				if(ok==0&&a[i][j]=='0') {
					pi=1;cout<<"ERR\n";ha[i]=0;break; //
				}
				else if('0'<=a[i][j]&&a[i][j]<='9'){
					ok=1;
					ha[i]=ha[i]*131+a[i][j]-'0'+1;
					sum=sum*10+a[i][j]-'0';
					//cout<<sum<<" ";
					
					if(g==1&&(sum>65535||sum<0)) {
						cout<<"ERR\n";pi=1;ha[i]=0;break;//
					}
					if(g==0&&(sum>255||sum<0)) {
						cout<<"ERR\n";pi=1;ha[i]=0;break;//<<sum
					}
				} 
				else if(a[i][j]==':') g=1,sum=0,ok=0;
				else if(a[i][j]=='.') g=0,sum=0,ok=0;
			}
			if(pi==0){
				for(int j=1;j<i;++j) if(ha[i]==ha[j]&&op[i]==op[j]) w[i]=1;
				if(w[i]==0) cout<<"OK\n";
				else cout<<"FAIL\n";
			}
		//	cout<<g;
		}
		if(used==0){
			//cout<<used;
			cin>>a[i];
			op[i]=1;
			bool ok=0,g=0;
			int len=a[i].length(),sum=0,num=0;
			for(int j=0;j<len;++j){
				if(ok==0&&a[i][j]=='0') {
					cout<<"ERR\n";ha[i]=0; pi=1;break;//
				}
				else if('0'<=a[i][j]&&a[i][j]<='9'){
					ok=1;
					ha[i]=ha[i]*131+a[i][j]-'0'+1;
					sum=sum*10+a[i][j]-'0';
					
					
					if(g==1&&(sum>65535||sum<0)) {
						cout<<"ERR\n";pi=1;ha[i]=0;break;//
					}
					if(g==0&&(sum>255||sum<0)) {
						cout<<"ERR\n";pi=1;ha[i]=0;break;//<<sum
					}
				} 
				else if(a[i][j]==':') g=1,sum=0,ok=0;
				else if(a[i][j]=='.') g=0,sum=0,ok=0;
			}
			if(pi==0){
				bool f=0;
				for(int j=1;j<i;++j){
					if(op[j]==0&&ha[j]==ha[i]&&w[j]==0){
						f=1;cout<<j<<endl;break;
					}
				}
				if(f==0) cout<<"FAIL\n";
			}
		}
	}

	return 0;
}
